package com.tarena.lbs.marketing.web.controller;

import com.tarena.lbs.base.protocol.exception.BusinessException;
import com.tarena.lbs.base.protocol.model.Result;
import com.tarena.lbs.base.protocol.pager.PageResult;
import com.tarena.lbs.marketing.web.service.ActivitiService;
import com.tarena.lbs.pojo.marketing.param.ActivityParam;
import com.tarena.lbs.pojo.marketing.query.ActivityQuery;
import com.tarena.lbs.pojo.marketing.vo.ActivityVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.ParseException;

@RestController
public class ActivityController {
    @Autowired
    private ActivitiService activitiService;
    @PostMapping("/admin/marketing/marketingActivity/info/list")
    public Result<PageResult<ActivityVO>> activityPage(@RequestBody ActivityQuery query)
        throws BusinessException {
        PageResult<ActivityVO> voPages=activitiService.activityPage(query);
        return new Result<>(voPages);
    }
    //活动新增提交
    @PostMapping("/admin/marketing/marketingActivity/info/save")
    public Result<Void> activitySave(@RequestBody ActivityParam param)
        throws BusinessException, ParseException {
        activitiService.activitySave(param);
        return Result.success();
    }
    //活动详情接口
    //路径传参{}自定义变量名称 controller入参要和变量一致
    @GetMapping("/admin/marketing/marketingActivity/info/detail/{id}")
    public Result<ActivityVO> activityDetail(@PathVariable Integer id)
    throws BusinessException {
        ActivityVO vo = activitiService.activityDetail(id);
        return new Result<>(vo);
    }

}
